package com.ustcinfo.study.hbase.xngroup.heson;

import org.apache.hadoop.hbase.client.Put;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class MyTest {
    public static void main(String[] args) {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/mysql-test";
        String username = "root";
        String password = "hesong";
        List<Put> list = new ArrayList<Put>();
        try {
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url,username,password);
            Statement st = conn.createStatement();
            PreparedStatement pt = conn.prepareStatement("select * from transfer_task_to");
            ResultSet rs = pt.executeQuery();
            while (rs.next()){
                String s1=rs.getString("id");
                String s2=rs.getString("task_id");
                String s3=rs.getString("create_time");
                String s4=rs.getString("start_time");
                String s5=rs.getString("out_filter_number");
                String s6=rs.getString("from_run_param");


                String s7=rs.getString("current_retry_times");
                String s8=rs.getString("retry_flag");
                String s9=rs.getString("parent_task_id");
                String s10=rs.getString("end_time");
                String s11=rs.getString("kill_time");
                String s12=rs.getString("failure_time");



                Put put = new Put(s1.getBytes());
                put.addColumn("F1".getBytes(), "id".getBytes(), s1.getBytes());
                put.addColumn("F1".getBytes(), "task_id".getBytes(), s2.getBytes());

                if (s3!=null){
                    put.addColumn("F1".getBytes(), "create_time".getBytes(), s3.getBytes());
                }
                if (s4!=null){
                    put.addColumn("F1".getBytes(), "start_time".getBytes(), s4.getBytes());
                }

                put.addColumn("F1".getBytes(), "out_filter_number".getBytes(), s5.getBytes());
                put.addColumn("F1".getBytes(), "from_run_param".getBytes(), s6.getBytes());


                put.addColumn("F2".getBytes(), "current_retry_times".getBytes(), s7.getBytes());
                put.addColumn("F2".getBytes(), "retry_flag".getBytes(), s8.getBytes());
                if(s9!=null){
                    put.addColumn("F2".getBytes(), "parent_task_id".getBytes(), s9.getBytes());
                }
                if(s10!=null){
                    put.addColumn("F2".getBytes(), "end_time".getBytes(), s10.getBytes());
                }
                if(s11!=null){
                    put.addColumn("F2".getBytes(), "kill_time".getBytes(), s11.getBytes());
                }
                if(s12!=null){
                    put.addColumn("F2".getBytes(), "failure_time".getBytes(), s12.getBytes());

                }

//                HBaseOperationDao.put("DB_TEST",put);
                list.add(put);

            }
            HBaseOperationDao.putList("DB_TEST",list);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
